package cn.com.haopy.yue.ai.admin.web;

import cn.com.haopy.yue.ai.admin.annotation.RequiresPermissionsDesc;
import cn.com.haopy.yue.ai.admin.service.AdminOrderService;
import cn.com.haopy.yue.ai.core.utils.ResponseUtil;
import cn.com.haopy.yue.ai.core.validator.Order;
import cn.com.haopy.yue.ai.core.validator.Sort;
import cn.com.haopy.yue.ai.db.entity.arisk.AIRiskOrder;
import cn.com.haopy.yue.ai.db.service.hos.AIRiskOrderService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: TODO
 * @Author DuTao
 * @Date 2025/4/1 10:39
 */
@RestController
@RequestMapping("/admin/order")
@RequiredArgsConstructor
@Slf4j
@Api(tags = "订单相关")
public class AdminAiRiskOrderController {
    @Autowired
    private AIRiskOrderService orderService;

    @Autowired
    private AdminOrderService adminOrderService;

    @RequiresPermissions("admin:order:list")
    @RequiresPermissionsDesc(menu = {"订单管理", "订单管理"}, button = "查询")
    @GetMapping("/list")
    @ApiOperation("列表")
    public Object list(@RequestParam(required = false) @ApiParam("订单编号") String orderNo,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer limit,
                       @Sort @RequestParam(defaultValue = "create_time") String sort,
                       @Order @RequestParam(defaultValue = "desc") String order) {
        Page<AIRiskOrder> listData = orderService.querySelective(null, orderNo, page, limit, sort, order);
        return ResponseUtil.okPage(listData);
    }

    @RequiresPermissions("admin:order:refund")
    @RequiresPermissionsDesc(menu = {"订单管理", "订单管理"}, button = "退款")
    @GetMapping("/refund")
    @ApiOperation("退款")
    public Object refund(@RequestParam @ApiParam("订单id") Integer id) {
        return adminOrderService.wxRefundOrder(id);
    }

}
